package com.shujia.wyh.day11;

import java.util.HashMap;
import java.util.Map;

/*
    Map集合，元素是由key-value键值对构成

    举例：
        <1001,"吴涛">
        <1002,"陈涛">
        <1003,"王硕">
        <1004,"张梦云">
        <1005,"王硕">

    注意事项：
        1、key的值是唯一，不能重复
        2、value是可以允许重复的

    Map集合成员方法：
        V put(K key,V value)
        V remove(Object key)
        void clear()
        boolean containsKey(Object key)
        boolean containsValue(Object value)
        boolean isEmpty()
        int size()


 */
public class MapDemo1 {
    public static void main(String[] args) {
//        Map map = new Map(); //Map是一个接口，而接口无法创建对象
        Map<Integer,String> map = new HashMap<>();

        //V put(K key,V value)
        //向Map集合中添加元素，一个元素是key-value格式
        map.put(1001,"吴涛");
        map.put(1002,"陈涛");
        map.put(1003,"王硕");
        map.put(1004,"张梦云");
        map.put(1005,"王硕");

        System.out.println(map);
        System.out.println("====================================");
        String s = map.put(1001, "小虎");//对同一个key进行赋值多次，value值会进行覆盖，返回旧的value值
        System.out.println(s);
        System.out.println(map);
        System.out.println("====================================");
        //V remove(Object key)
        String s1 = map.remove(1005);
        System.out.println(s1);
        System.out.println(map);
        System.out.println("====================================");
        //void clear()
//        map.clear();
//        System.out.println(map);
        System.out.println("====================================");
        //boolean containsKey(Object key)
        System.out.println(map.containsKey(1001));
        System.out.println("====================================");
        //boolean containsValue(Object value)
        System.out.println(map.containsValue("小虎"));
        System.out.println("====================================");
        //boolean isEmpty()
        System.out.println(map.isEmpty());
        System.out.println("====================================");
        //int size()
        System.out.println(map);
        System.out.println(map.size());
    }
}
